layui.config({
    base: '/layui/extend/'
}).use(['form', 'layer', 'dtree', 'upload', 'element'], function () {
    $ = layui.jquery;
    var form = layui.form
        , layer = parent.layer === undefined ? layui.layer : top.layer
        , element = layui.element
        , upload = layui.upload;

    var uploadInst = upload.render({
        elem: '#uploadFile',
        url: '/document/upload',
        method: 'POST',
        size: 1024 * 50,
        accept: 'file',
        auto: false,
        bindAction: '#commit',
        async: false,
        choose: function (obj) {
            files= this.files = obj.pushFile();
            //读取本地文件
            obj.preview(function (index, file, result){
                document.getElementById("file").value = file.name;
            })
        },
        before: function () {
            this.data = {
                id: $('#id').val(),
                projectId: $('#projectId').val(),
                fileName: $('#fileName').val(),
                fileType: $('#fileType').val(),
                uploadPerson: trueName,
            };
            index2 = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        }
        , done: function (res, index, upload) {
            console.log(res);
            if (res.code == 0) {
                setTimeout(function () {
                    top.layer.close(index2);
                    top.layer.msg("操作成功！",{icon: 6});
                    layer.closeAll("iframe");
                    // 刷新父页面
                    parent.location.reload();
                },500);
            }
        }
        , error: function (index, upload) {
            layer.msg("上传失败")
        }
    });


    // var uploadInst = upload.render({
    //     elem: '#uploadFile'
    //     , url: '/document/upload'
    //     , method: 'POST'
    //     , size: 1024 * 50
    //     , accept: 'file'
    //     , multiple: true
    //     , auto: false
    //     , bindAction: '#commit'
    //     // , contentType: false
    //     , before: function () {
    //         this.data = {
    //             id: $('#id').val(),
    //             projectId: $('#projectId').val(),
    //             fileName: $('#fileName').val(),
    //             fileType: $('#fileType').val(),
    //             uploadPerson: trueName,
    //         };
    //     }
    //     , done: function (res, index, upload) {
    //         console.log(res);
    //         if (res.code == 0) {
    //             alert(1)
    //             layer.msg("上传成功！",{icon: 6});
    //             // 刷新父页面
    //             parent.location.reload();
    //         } else
    //             this.error(index, upload);
    //     }
    //     , error: function (index, upload) {
    //         layer.msg("上传失败")
    //     }
    // });

});